<template>
  <div class="app-container">
    <div class="filter-container">
      <el-input
        v-model="listQuery.owner"
        placeholder="账号"
        style="width: 100px;"
      />
      <el-date-picker
        v-model="listQuery.startDate"
        type="date"
        placeholder="起始日期"
        style="width: 140px;"
        value-format="yyyy-MM-dd"
      />
      <el-date-picker
        v-model="listQuery.endDate"
        type="date"
        placeholder="截止日期"
        style="width: 140px;"
        value-format="yyyy-MM-dd"
      />
      <el-button class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">
        查询
      </el-button>
    </div>
    <el-table
      v-loading="listLoading"
      :data="list"
      border
      fit
      stripe
      highlight-current-row
      style="width: 100%;"
    >
      <el-table-column
        type="index"
        width="50"
      />
      <el-table-column
        prop="owner"
        label="操作账号"
        width="100"
      />
      <el-table-column
        prop="authType"
        label="授权类型"
        width="100"
        :formatter="authTypeFormatter"
      />
      <el-table-column
        prop="requestDate"
        label="请求时间"
        width="160"
      />
      <el-table-column
        prop="path"
        label="请求地址"
        width="140"
      />
      <el-table-column
        prop="clientIp"
        label="客户端ip"
        width="100"
      />
      <el-table-column
        prop="requestParam"
        label="请求参数"
      /> <el-table-column
        prop="response"
        label="返回值"
      />
      <el-table-column
        prop="timeConsuming"
        label="响应时间"
        width="100"
      />
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.limit"
      @pagination="listSysErrorLog"
    />
  </div>
</template>

<script>
import { listSysErrorLog } from '@/api/monitor/errorlog'
import Pagination from '@/components/Pagination/index'
import DateUtil from '@/utils/DateUtil'
import PageUtil from '@/utils/PageUtil'
import ComboConst from '@/utils/ComboConst'

export default {
  components: { Pagination },
  data() {
    return {
      tableKey: 0,
      list: null,
      total: 0,
      listLoading: true,
      listQuery: {
        startDate: DateUtil.getSystemDateDiff(-10),
        endDate: DateUtil.getSystemDate(),
        owner: '',
        page: 1,
        limit: 20
      }
    }
  },
  created() {
    this.listSysErrorLog()
  },
  methods: {
    authTypeFormatter(row) {
      return PageUtil.formatValue(ComboConst.authTypeAllOptions, row.authType)
    },
    listSysErrorLog() {
      this.listLoading = true
      listSysErrorLog(this.listQuery).then(response => {
        this.list = response.data.data
        this.total = response.data.total
        setTimeout(() => {
          this.listLoading = false
        }, 500)
      })
    },
    // 按钮查询
    handleFilter() {
      this.listQuery.page = 1
      this.listSysErrorLog()
    }
  }
}
</script>
